{extend name="base/base" /}
{block name="main"}
<style>
.layui-form-pane .layui-form-label{width: 160px;}
.layui-form-pane .layui-input-block{
        margin-left: 160px;
}
.layui-form-select dl{z-index: 99999;}
</style>
<form id="form" method="post" class="layui-form layui-form-pane" action="{:url('/admin/article-edit')}">

	
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>文章标题</label>
        <div class="layui-input-block">
            <input type="text" name="title" placeholder="请输入" {if condition="isset($list['a_id']) && $list['cate_id'] == 19"}readonly{/if} autocomplete="off" class="layui-input"
                   value="{:isset($list.title)?$list.title:''}" lay-verify="required" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">&nbsp;</span>文章简述</label>
        <div class="layui-input-block">
            <input type="text" name="desc" placeholder="请输入" autocomplete="off" class="layui-input"
                   value="{:isset($list.desc)?$list.desc:''}" >
        </div>
    </div>

     <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>栏目</label>
        <div class="layui-input-block">
			<select name="cate_id" lay-filter="cate_id" lay-verify="required">
				<option value="0">顶级分类</option>
				{$cate_option_str|raw}
            </select>
        </div>
    </div>
	
	 <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;">*&nbsp;</span>是否隐藏</label>
        <div class="layui-input-block">
            {form:radio name="is_hide" value="$list['is_hide']" list="['0'=>'否','1'=>'是']"}
        </div>
    </div>

    <div class="layui-form-item"><!--(177*106)-->
        <label class="layui-form-label" style="margin-top: 20px;"><span style="color:red;">&nbsp;</span>封面图片{$img_size}</label>
        <div class="layui-input-block">
            <img class="layui-upload-img userFaceBtn userAvatar" style="margin-left: 10px;height:80px;" id="userFace" src="{:isset($list.img)?$list.img:''}">
            <input type="hidden" value="{:isset($list.img)?$list.img:''}" name="img" id="head" lay-verify="">
            <button type="button" class="layui-btn layui-btn-primary userFaceBtn"><i class="layui-icon">&#xe67c;</i> 上传</button>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label"><span style="color:red;"></span>排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" placeholder="请输入"  value="{:isset($list.sort)?$list.sort:''}"  autocomplete="off" class="layui-input">
        </div>
    </div>
    
    <div class="layui-form-item" style="padding-bottom: 30px">
        <div class="layui-input-block">
            <input type="hidden" name="a_id" value="{:isset($list['a_id'])?$list['a_id']:''}">
            <input type="hidden" name="__token__" id="token" value="{$Request.token}"/>
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
{css href="/form-select/formSelects-v4.css" /}
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js?v=0.0.1"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    layui.config({
        base: '/form-select/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    layui.use(['form', 'jquery', 'formSelects','upload','layedit'], function () {
        var formSelects = layui.formSelects, form = layui.form, $ = layui.jquery,upload = layui.upload;

        // var layedit = layui.layedit;
        // var info = layedit.build('info'); //建立编辑器
        

        //上传头像
		upload.render({
			elem: '.userFaceBtn',
			url: "{:url('/admin/upload')}",
			accept:'images',
			acceptMime:'image/*',
			done: function(data){
				var icon=5;
				if(!data.code){
					icon=6;
					$('#userFace').attr('src',data.data.src);
					$('#head').val(data.data.src);
				}
				layer.msg(data.msg, {icon:icon,time: 1500});
			},
			error: function(){
				layer.msg('上传失败', {icon:icon,time: 1500});
			}
		});

        form.on("select(cate_id)",function(data){
            if(data.value == 31){
                $("#img_size").html('234*234');
            }else{
                $("#img_size").html('375*280');
            }
        });

        formSelects.on('selectId', function (id, vals, val, isAdd, isDisabled) {
            $('#group_id').val(layui.formSelects.value(id, 'val'));
        }, true);
        //表单验证
        form.verify({
            title: function (value, item) { //value：表单的值、item：表单的DOM对象
                var msg;
                $.ajax({
                    async: false,
                    url: "{:url('/admin/-check')}",
                    data: {title: value},
                    success: function (data) {
                        if (data.code== 0) {
                            msg = data.msg;
                        }
                    }
                });
                return msg;
            },
            password:function(value, item){
                if(value){
                    if(!(/^[\w\W]{6,25}$/.test(value))){
                        return '用户名不能全为数字';
                    }
                }
            },
            uploadimg:function(value, item){
                if(!value){
                    return '请上传图片';
                }
            },
            infos: function(value) {
                return layedit.sync(info);
            }
        });
        //表单提交
        form.on("submit(*)", function (data) {
            var obj = $(this);
            obj.attr("disabled", "disabled").addClass("layui-disabled");
            $.post(data.form.action, data.field, function (data) {
                var icon = 5;
                if (data.code) {
                    icon = 6;
                }
                layer.msg(data.msg, {icon: icon, time: 1500}, function () {   //提示的插件，可以使用alert代替
                    if (data.code) {
                        setTimeout(function () {
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        $('#token').val(data.data.token);
                        obj.removeAttr("disabled").removeClass("layui-disabled");
                    }
                });
            }, 'json');
            return false;
        });
    });


</script>
{/block}